#ifndef KMY_SCREEN_INTERFACE_H
#define KMY_SCREEN_INTERFACE_H

#include "KmyITexture.h"
#include "KmyImagePak.h"
#include "DrawTask.h"
//#include "KmyWorld.h"

/**
  * 画布接口，用来派生出屏幕
  */
class KmyICanvas
{
public:
    KmyICanvas();
    virtual ~KmyICanvas();

    int WIDTH, HEIGHT;

    static const int SCREEN_TYPE_800_600 = 1;
    static const int SCREEN_TYPE_960_544 = 2;
    static const int SCREEN_TYPE_400_240 = 3;
    static const int SCREEN_TYPE_320_240 = 4;
    static const int SCREEN_TYPE_480_272 = 5;

//    KmyWorld *world;
//    /** 显示列表初始化（世界 该画的东西放入列表）*/
//    void update();
//    /** updateGL, 用来启动paintGL */
//    virtual void updateGLx() = 0;

    /** 添加画图任务 */
    virtual DrawTask* addDrawTaskImageF(KmyITexture *img,
                                int dx, int dy, int z,
                       float alpha=1, float angle = 0, int flip = 0);
    /** 添加画图任务 */
    virtual DrawTask* addDrawTaskImageF2(KmyITexture *img,
                                 int sx, int sy, int sw, int sh,
                                 int dx, int dy, int dw, int dh, int z,
                       float alpha=1, float angle = 0, int flip = 0);
    /** 添加画图任务 */
    virtual DrawTask* addDrawTaskImageS(KmyImagePak *imgpak, int img_id,
                               int dx, int dy,
                               int z,
                      float alpha=1, float angle = 0, int flip = 0);
    /** 添加画图任务 */
    virtual DrawTask* addDrawTaskImage(KmyImagePak *imgpak, int img_id,
                               int dx, int dy, int dw, int dh,
                               int z,
                      float alpha=1, float angle = 0, int flip = 0);
    /** 添加画图任务 */
    virtual DrawTask* addDrawTaskRegion(KmyImagePak *imgpak, int img_id,
            int sx, int sy, int sw, int sh,
            int dx, int dy, int dw, int dh, int z,
            float alpha=1, float angle = 0, int flip = 0);

    /** 同时画多个图（同z，同角度） */
    virtual DrawTask* addDrawTaskMultiImage(KmyITexture *img,
                                            int num, St_Rect* srects, St_Rect2* drects,
                                            int z, float alpha=1, float angle=0);
    /** 同时画一个图多次（同z，同角度，同翻转） */
    virtual DrawTask* addDrawTaskDupliImage(KmyITexture *img,
                                            St_Rect* srect, int dnum, St_Rect2* drects,
                                            int z, float alpha=1, float angle=0);

//    void bindTexturePlus(KmyITexture *tex);
//    void deleteTexturePlus(KmyITexture *tex);

    bool is_need_repaint;

    void addDrawTask(DrawTask *dt);

protected:
    virtual void paintGL() = 0;

    DrawTaskChainNode *draw_task_head;
    DrawTaskChainNode *draw_task_head_bak;


//    void removeDrawTask(DrawTask *dt);


    void executeDrawTaskList();

//    virtual void drawRegion(KmyITexture *image,
//                            int sx, int sy, int sw, int sh,
//                            int dx, int dy, int dw, int dh,
//                            float z,
//                            float alpha=1, int angle = 0, int flip = 0) = 0;
    virtual void runDrawTask(DrawTask* dt) = 0;

private:
    void swapTaskLiskBuff();
    void clearDrawTask();

    bool is_drawing;
};

#endif // SCREENINTERFACE_H
